// 对axios请求封装
import axios from 'axios'
// 定义post请求体的数据格式为json
axios.defaults.headers.post['Content-Type'] = 'application/json'
// 定义域名
axios.defaults.baseURL = 'https://www.fastmock.site/mock/cfa7e0bcaaf02ecc4c35191122680d58'

// 定义post请求
const post = (url, data = {}) => {
  return new Promise((resolve, reject) => {
    axios
      .post(url, data)
      .then((response) => {
        resolve(response)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
// 定义get请求
const get = (url, params = {}) => {
  return new Promise((resolve, reject) => {
    axios
      .get(url, { params })
      .then((response) => {
        resolve(response)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
export { post, get }
